home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWViews / Include / FWEdView.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  6.8 KB  |  207 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWEdView.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWEDVIEW_H
  11. #define FWEDVIEW_H
  12.  
  13. //----------------------------------------------------------------------------------------
  14. // Imported Classes
  15. //----------------------------------------------------------------------------------------
  16.  
  17. #ifndef FWFONT_H
  18. #include "FWFont.h"
  19. #endif
  20.  
  21. #ifndef FWVIEW_H
  22. #include "FWView.h"
  23. #endif
  24.  
  25. #ifndef FWNOTIFR_H
  26. #include "FWNotifr.h"
  27. #endif
  28.  
  29. #ifdef FW_BUILD_MAC
  30. #include "TextEdit.h"
  31. #endif
  32.  
  33. //========================================================================================
  34. //    Forward Declaration
  35. //========================================================================================
  36.  
  37. class FW_CString;
  38. class FW_CSuperView;
  39. class FW_CFont;
  40.  
  41.  
  42. //========================================================================================
  43. // class FW_CEditView
  44. //========================================================================================
  45. // FW_CEditView is a wrapper to the Macintosh text-edit, see Inside Macintosh: Text
  46.  
  47. class FW_CEditView: public FW_CView, public FW_MNotifier
  48. {
  49. public:
  50.     FW_DECLARE_CLASS
  51.     FW_DECLARE_AUTO(FW_CEditView)
  52.  
  53.     // EditView attributes
  54.     enum AttrEnum
  55.     {
  56.         kDrawBox         = 0x01,        // draw a 1 pixel frame
  57.         kReadOnly        = 0x02,        // not implemented yet
  58.         kWordWrap        = 0x04,        // wrap long lines
  59.         kAutoScroll        = 0x08,        // scroll when text is out of view
  60.         kOutlineHilite    = 0x10,        // show selection in inactive text edit
  61.         kTextBuffering    = 0x20,        // for 2-byte scripts
  62.         kInlineInput    = 0x40,        // use keyboard input method
  63.         kTextServices    = 0x80        // see Inside Macintosh: Text
  64.     };
  65.                     
  66.     FW_CEditView (Environment* ev, 
  67.                     FW_CSuperView* container, 
  68.                     ODID  viewId,
  69.                     const FW_CRect& bounds,
  70.                     const FW_CString& text, 
  71.                     const FW_CFont& font = FW_kNormalFont,
  72.                     short maxChars = FW_MAXINT16, 
  73.                     unsigned short attributes = FW_CEditView::kDrawBox + 
  74.                                                 FW_CEditView::kWordWrap + 
  75.                                                 FW_CEditView::kAutoScroll);
  76.  
  77.     FW_CEditView (Environment* ev, 
  78.                     FW_CSuperView* container, 
  79.                     ODID  viewId,
  80.                     const FW_CRect& bounds);
  81.                     
  82.     FW_CEditView(Environment* ev);
  83.  
  84.     ~FW_CEditView ();
  85.     
  86.     // ---- Getters
  87.     FW_Boolean             HasBox() const;
  88.     FW_Boolean             HasWordWrap() const;
  89.     FW_Boolean             HasAutoScroll() const;
  90.     unsigned short        GetEditAttributes() const;
  91.     FW_ByteCount        GetMaxChars(Environment* ev) const;
  92.  
  93.     FW_CString             GetText (Environment* ev) const;
  94.     FW_ByteCount         GetTextLength (Environment * ev) const;
  95.  
  96.     FW_PlatformHandle    GetPlatformEditHandle(Environment* ev) const;
  97.             
  98.     // ---- Text Events
  99.     virtual void        DoTECommand (Environment* ev, ODCommandID id, FW_Boolean useScrap);
  100.     virtual FW_Boolean     InputCharKey (Environment* ev, char c);
  101.  
  102.     // ---- Text changes
  103.     virtual void         SetText (Environment* ev, const FW_CString& text);
  104.     virtual void         ClearText (Environment* ev);
  105.     virtual void         InsertText(Environment* ev, const FW_CString& textToInsert, short offset);
  106.     void                 SetFont (Environment * ev, const FW_CFont &font);
  107.  
  108.     // ---- Text Selection
  109.     FW_CString             GetSelectedText(Environment* ev) const;
  110.     void                 GetSelectionRange(Environment* ev, short& startOffset, short& endOffset) const;
  111.     void                 SetSelectedText(Environment* ev, const FW_CString& newText);
  112.     void                 SelectText (Environment* ev, short startOffset, short endOffset);
  113.     void                 SelectAll (Environment* ev);
  114.     
  115.     // ---- FW_MEventHandler
  116.     virtual FW_Boolean     DoIdle (Environment* ev, const FW_CNullEvent& event);
  117.     virtual FW_Boolean     DoMouseDown (Environment* ev, const FW_CMouseEvent& event);
  118.     virtual FW_Boolean     DoVirtualKey (Environment* ev, const FW_CVirtualKeyEvent & event);
  119.     virtual FW_Boolean     DoCharKey (Environment* ev, const FW_CCharKeyEvent& event);
  120.     virtual FW_Boolean     DoAdjustMenus (Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot);
  121.     virtual FW_Boolean     DoMenu     (Environment* ev, const FW_CMenuEvent& event);
  122.     virtual void         ActivateTarget (Environment* ev, FW_Boolean tabSelection);
  123.     virtual void         DeactivateTarget (Environment* ev);
  124.     virtual FW_Boolean     WantsToBeTarget (Environment* ev);
  125.     virtual void         SetVisible(Environment* ev, FW_Boolean visible, FW_Boolean propagate);
  126.     
  127.     // ---- FW_CView
  128.     virtual FW_Boolean     AdjustCursor (Environment* ev, ODFacet* odFacet, const FW_CPoint& where);
  129.     virtual void         Draw (Environment* ev, ODFacet* facet, ODShape* invalidShape);
  130.     virtual void        LocationChanged (Environment* ev, const FW_CPoint& oldLocation);
  131.     virtual void        SizeChanged (Environment* ev, const FW_CPoint& oldSize);
  132.  
  133.     // ----- Archiving -----
  134.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream) const;
  135.     virtual void        InitializeFromStream(Environment* ev, FW_CReadableStream& stream);
  136.     static void*        Create(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  137.     static void            Destroy(void* object, FW_ClassTypeConstant type);
  138.     
  139. protected: 
  140.     void                 PrivSelectAll ();
  141.     void                PrivEnableEditMenu(Environment *ev, FW_Boolean enable);
  142.  
  143.     // ---- Utilities
  144.     void                 Initialize(Environment* ev, const FW_CString& str, const FW_CFont& font);
  145.     FW_CRect             GetTextBounds (Environment* ev);
  146.     void                 MacAdjustRects (Environment* ev, FW_CGraphicContext & gc);
  147.     void                 MacSetRects (Environment* ev);
  148.     inline TERec *         MacTE() const { return *fMacTEHandle; }
  149.     FW_Boolean          PrivCheckMaxChars(long numChars);
  150.     
  151. private:
  152.     TEHandle            fMacTEHandle;
  153.     short                fMaxChars;
  154.     unsigned short        fEditAttributes;
  155. };
  156.  
  157.  
  158. //========================================================================================
  159. //     Inlines
  160. //========================================================================================
  161.  
  162. inline    FW_PlatformHandle    FW_CEditView::GetPlatformEditHandle(Environment*) const
  163. {
  164. #ifdef FW_BUILD_MAC
  165.     return (FW_PlatformHandle)fMacTEHandle;
  166. #endif
  167. }
  168.  
  169. inline    FW_ByteCount    FW_CEditView::GetMaxChars(Environment*) const
  170. {
  171. #ifdef FW_BUILD_MAC
  172.     return (FW_ByteCount)fMaxChars;
  173. #endif
  174. }
  175.  
  176. //---------------------------------------------------------------------------------------------------
  177. //     attributes
  178. //---------------------------------------------------------------------------------------------------
  179.  
  180. inline FW_Boolean FW_CEditView::HasBox() const
  181. {
  182.     return fEditAttributes & FW_CEditView::kDrawBox;
  183. }
  184.  
  185. inline FW_Boolean FW_CEditView::HasWordWrap() const
  186. {
  187.     return fEditAttributes & FW_CEditView::kWordWrap;
  188. }
  189.  
  190. inline FW_Boolean FW_CEditView::HasAutoScroll() const
  191. {
  192.     return fEditAttributes & FW_CEditView::kAutoScroll;
  193. }
  194.  
  195. inline unsigned short FW_CEditView::GetEditAttributes() const
  196. {
  197.     return fEditAttributes;
  198. }
  199.  
  200. inline void FW_CEditView::SelectAll (Environment* ev)
  201. {
  202.     SelectText(ev, 0, FW_MAXINT16);
  203. }
  204.  
  205. #endif // FWEDVIEW_H
  206.  
  207.